import * as step from '@flow-step/step-toolkit'
import fs from 'fs'

export async function installKubectl(version: string) {
    try {
        let toolName: string = 'kubectl'
        step.info(`Try to install the kubectl with version ${version}`)

        const installPath = await step.tool.install(toolName, version)
        fs.chmodSync(`${installPath}/kubectl-${version}`, 0o755)

        step.addPath(installPath)

        return `${installPath}/kubectl-${version}`
    } catch (err) {
        throw new Error(`failed to install kubectl but err: ${err}`)
    }
}